Skip to content

Fixing percent error in monte_carlo.rs #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2018

Conversation

Gathros
Copy link
Contributor

@Gathros Gathros commented Sep 14, 2018

@Gathros Gathros added the Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) label Sep 14, 2018
@@ -26,5 +26,5 @@ fn monte_carlo(n: i64) -> f64 {
fn main() {
let pi_estimate = monte_carlo(10000000);

println!("Percent error is {:.3}%", (100.0 * (PI - pi_estimate) / PI));
println!("Percent error is {:.3}%", (100.0 * (PI - pi_estimate).abs() / PI));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!
In the other PRs we also changed the order of (PI - pi_estimate) to (pi_estimate - PI), so that the theoretical value gets subtracted from the experimental one.
It doesn't change the outcome, it's just nicer, so can you maybe change (100.0 * (PI - pi_estimate).abs() / PI) to (100.0 * (pi_estimate - PI).abs() / PI)?

@june128
Copy link
Member

june128 commented Sep 14, 2018

Looks good. Thanks for the changes!

@june128 june128 merged commit acc0289 into algorithm-archivists:master Sep 14, 2018
@june128 june128 mentioned this pull request Sep 14, 2018
6 tasks
@Gathros Gathros deleted the monte_rust branch September 15, 2018 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants